<template>
    <div>
        <pagination
            v-model="pageIndex"
            :page-count="total"
            @prev="Favorite.$prev"
            @next="Favorite.$next"
        ></pagination>

        <xin-swipe-cell
            :label="data.desc"
            :title="data.title"
            v-for="(data, index) in Favorite"
            :key="data._id"
            :button="swipeButton"
            @click="handleClick($event, data)"
        >
        </xin-swipe-cell>
    </div>
</template>

<script>
import { mapState } from "vuex";
import $store from "@/store/index";
export default {
    components: {},
    computed: {
        ...mapState({
            Favorite: (state) => state.user.Favorite,
            total: (state) => state.user.Favorite.total,
        }),
    },
    mounted() {
        this.FavoriteTo(1);
    },
    data() {
        return {
            swipeButton: [
                {
                    type: "primary",
                    name: "查看",
                },
                {
                    type: "danger",
                    name: "删除",
                },
            ],
            pageIndex: 1,
        };
    },
    methods: {
        handleClick({ name }, data) {
            switch (name) {
                case "查看":
                    $store.commit("firstPageXinSetTo", data);
                    console.log(data);
                    wx.navigateTo({ url: "/pages/index/index" });
                    break;
                case "删除":
                    $store
                        .dispatch("changeLike", {
                            isLiked: false,
                            _id: data._id,
                        })
                        .then(() => this.Favorite.$refresh());
                    break;
            }
        },
        FavoriteTo(index) {
            this.Favorite.$to(index - 1);
            this.Favorite.$refresh();
        },
    },
};
</script>

<style lang="less" scoped>
.btn {
    height: 100%;
}
</style>